package com.boco.ibssystem.common.config;

import com.boco.ibssystem.common.interceptor.ResponseResultInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {

//    @Bean
//    public FilterRegistrationBean characterEncodingFilter(){
//        FilterRegistrationBean<CharacterEncodingFilter> characterEncodingFilterBean = new FilterRegistrationBean<>();
//        characterEncodingFilterBean.setFilter(new CharacterEncodingFilter());
//        characterEncodingFilterBean.setEnabled(true);
//        characterEncodingFilterBean.addUrlPatterns("/**");
//        characterEncodingFilterBean.setOrder(1);
//        return characterEncodingFilterBean;
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResponseResultInterceptor()).excludePathPatterns("/**.html","/swagger-ui.html**","/webjars/**","/v2/api-docs","/swagger-resources/**","/swagger-resources");
    }

    @Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter(){
        return  new HiddenHttpMethodFilter();
    }
}
